package xyz.fuqufyb.aec.controller;

import com.spingcloud.travel.common.JsonResult;
import com.spingcloud.travel.common.TableResult;
import com.springcloud.travel.entity.Scenery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import xyz.fuqufyb.aec.feign.scenery.SceneryFeign;

@RestController
@RequestMapping("/sys/scenery")
public class SysSceneryController {
    @Autowired
    private SceneryFeign sceneryFeign;

    @RequestMapping("/table")
    public TableResult table(Integer page, Integer limit) {
        try {
            TableResult table = sceneryFeign.getTable(page, limit);
            return table;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @PostMapping("/add")
    public JsonResult add(Scenery scenery) {
        try {
            boolean insert = sceneryFeign.addScenery(scenery);
            if (insert) {
                return JsonResult.getJsonResultBySuccess();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return JsonResult.getJsonResultByFail();
    }

    @RequestMapping("/del")
    public JsonResult del(@RequestParam(value = "ids") String[] ids) {
        try {
            boolean insert = sceneryFeign.delScenery(ids);
            if (insert) {
                return JsonResult.getJsonResultBySuccess();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return JsonResult.getJsonResultByFail();
    }

    @RequestMapping("/update")
    public JsonResult update(Scenery scenery) {
        try {
            boolean insert = sceneryFeign.updateScenery(scenery);
            System.out.println("SysSceneryController.update");
            if (insert) {
                return JsonResult.getJsonResultBySuccess();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return JsonResult.getJsonResultByFail();

    }
}
